🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / testing / src / commonMain / kotlin / org / meshtastic / core / testing / FakeRadioInterfaceService.kt
Displaying Raw • Download
core/testing/src/commonMain/kotlin/org/meshtastic/core/testing/FakeRadioInterfaceService.kt 3ca87fa0323214c7204c9d37acfe9d4b6ab6ea8b (3ca87fa0) Text, 4.69 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.testing
Tff7b72import T7ee787kotlinx.coroutines.CoroutineScope
Tff7b72import T7ee787kotlinx.coroutines.MainScope
Tff7b72import T7ee787kotlinx.coroutines.channels.Channel
Tff7b72import T7ee787kotlinx.coroutines.flow.Flow
Tff7b72import T7ee787kotlinx.coroutines.flow.MutableSharedFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.MutableStateFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.StateFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.asFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.receiveAsFlow
Tff7b72import T7ee787org.meshtastic.core.model.ConnectionState
Tff7b72import T7ee787org.meshtastic.core.model.DeviceType
Tff7b72import T7ee787org.meshtastic.core.model.InterfaceId
Tff7b72import T7ee787org.meshtastic.core.model.MeshActivity
Tff7b72import T7ee787org.meshtastic.core.repository.RadioInterfaceService
T8b949e/**
* A test double for [RadioInterfaceService] that provides an in-memory implementation.
*
* The [connectionState] here mirrors the transport-level semantics of the real implementation. In production, only
* [MeshConnectionManager][org.meshtastic.core.repository.MeshConnectionManager] observes this flow; tests should verify
* that bridging behavior rather than consuming it directly from UI/feature test code (use
* [FakeServiceRepository.connectionState] instead).
*/
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooManyFunctionsTa5d6ff"Tb4b4b4)
Tff7b72class T56d364FakeRadioInterfaceServiceTb4b4b4(Tff7b72override Tff7b72val Te6edf3serviceScopeTb4b4b4: Te6edf3CoroutineScope Tff7b72= Te6edf3MainScopeTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4: Te6edf3RadioInterfaceService Tb4b4b4{
Tff7b72override Tff7b72val Te6edf3supportedDeviceTypesTb4b4b4: Te6edf3ListTff7b72<Te6edf3DeviceTypeTff7b72> Tff7b72= Te6edf3emptyListTb4b4b4(Tb4b4b4)
T8b949e/** Transport-level connection state (raw hardware link status). */
Tff7b72private Tff7b72val Te6edf3_connectionState Tff7b72= Te6edf3MutableStateFlowTff7b72<Te6edf3ConnectionStateTff7b72>Tb4b4b4(Te6edf3ConnectionStateTb4b4b4.Te6edf3DisconnectedTb4b4b4)
Tff7b72override Tff7b72val Te6edf3connectionStateTb4b4b4: Te6edf3StateFlowTff7b72<Te6edf3ConnectionStateTff7b72> Tff7b72= Te6edf3_connectionState
Tff7b72private Tff7b72val Te6edf3_currentDeviceAddressFlow Tff7b72= Te6edf3MutableStateFlowTff7b72<Tffa657String?Tff7b72>Tb4b4b4(Tff7b72nullTb4b4b4)
Tff7b72override Tff7b72val Te6edf3currentDeviceAddressFlowTb4b4b4: Te6edf3StateFlowTff7b72<Tffa657String?Tff7b72> Tff7b72= Te6edf3_currentDeviceAddressFlow
T8b949e// Use an unbounded Channel to mirror SharedRadioInterfaceService semantics. A MutableSharedFlow would
T8b949e// hide the stop/start backlog bug that motivated the resetReceivedBuffer() API.
Tff7b72private Tff7b72val Te6edf3_receivedData Tff7b72= Te6edf3ChannelTff7b72<Te6edf3ByteArrayTff7b72>Tb4b4b4(Te6edf3ChannelTb4b4b4.Te6edf3UNLIMITEDTb4b4b4)
Tff7b72override Tff7b72val Te6edf3receivedDataTb4b4b4: Te6edf3FlowTff7b72<Te6edf3ByteArrayTff7b72> Tff7b72= Te6edf3_receivedDataTb4b4b4.Te6edf3receiveAsFlowTb4b4b4(Tb4b4b4)
Tff7b72private Tff7b72val Te6edf3_meshActivity Tff7b72= Te6edf3MutableSharedFlowTff7b72<Te6edf3MeshActivityTff7b72>Tb4b4b4(Tb4b4b4)
Tff7b72override Tff7b72val Te6edf3meshActivityTb4b4b4: Te6edf3FlowTff7b72<Te6edf3MeshActivityTff7b72> Tff7b72= Te6edf3_meshActivityTb4b4b4.Te6edf3asFlowTb4b4b4(Tb4b4b4)
Tff7b72private Tff7b72val Te6edf3_connectionError Tff7b72= Te6edf3MutableSharedFlowTff7b72<Tffa657StringTff7b72>Tb4b4b4(Tb4b4b4)
Tff7b72override Tff7b72val Te6edf3connectionErrorTb4b4b4: Te6edf3FlowTff7b72<Tffa657StringTff7b72> Tff7b72= Te6edf3_connectionErrorTb4b4b4.Te6edf3asFlowTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3sentToRadio Tff7b72= Te6edf3mutableListOfTff7b72<Te6edf3ByteArrayTff7b72>Tb4b4b4(Tb4b4b4)
Tff7b72var Te6edf3connectCalled Tff7b72= Tff7b72false
Tff7b72var Te6edf3restartTransportCalledTb4b4b4: Tffa657Boolean Tff7b72= Tff7b72false
Te6edf3private Tff7b72set
Tff7b72override Tff7b72fun Td2a8ffisMockTransportTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657Boolean Tff7b72= Tff7b72true
Tff7b72override Tff7b72fun Td2a8ffsendToRadioTb4b4b4(Te6edf3bytesTb4b4b4: Te6edf3ByteArrayTb4b4b4) Tb4b4b4{
Te6edf3sentToRadioTb4b4b4.Te6edf3addTb4b4b4(Te6edf3bytesTb4b4b4)
Tb4b4b4}
Tff7b72override Tff7b72fun Td2a8ffconnectTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3connectCalled Tff7b72= Tff7b72true
Tb4b4b4}
Tff7b72override Tff7b72suspend Tff7b72fun Td2a8ffdisconnectTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3connectCalled Tff7b72= Tff7b72false
Tb4b4b4}
Tff7b72override Tff7b72suspend Tff7b72fun Td2a8ffrestartTransportTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3restartTransportCalled Tff7b72= Tff7b72true
Tb4b4b4}
Tff7b72override Tff7b72fun Td2a8ffgetDeviceAddressTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657String? Tff7b72= Te6edf3_currentDeviceAddressFlowTb4b4b4.Te6edf3value
Tff7b72override Tff7b72fun Td2a8ffsetDeviceAddressTb4b4b4(Te6edf3deviceAddrTb4b4b4: Tffa657String?Tb4b4b4)Tb4b4b4: Tffa657Boolean Tb4b4b4{
Te6edf3_currentDeviceAddressFlowTb4b4b4.Te6edf3value Tff7b72= Te6edf3deviceAddr
Tff7b72return Tff7b72true
Tb4b4b4}
Tff7b72override Tff7b72fun Td2a8fftoInterfaceAddressTb4b4b4(Te6edf3interfaceIdTb4b4b4: Te6edf3InterfaceIdTb4b4b4, Te6edf3restTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Tffa657String Tff7b72= Ta5d6ff"Tffd700$Te6edf3interfaceIdTa5d6ff:Tffd700$Te6edf3restTa5d6ff"
Tff7b72override Tff7b72fun Td2a8ffonConnectTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3_connectionStateTb4b4b4.Te6edf3value Tff7b72= Te6edf3ConnectionStateTb4b4b4.Te6edf3Connected
Tb4b4b4}
Tff7b72override Tff7b72fun Td2a8ffonDisconnectTb4b4b4(Te6edf3isPermanentTb4b4b4: Tffa657BooleanTb4b4b4, Te6edf3errorMessageTb4b4b4: Tffa657String?Tb4b4b4) Tb4b4b4{
Te6edf3_connectionStateTb4b4b4.Te6edf3value Tff7b72= Te6edf3ConnectionStateTb4b4b4.Te6edf3Disconnected
Tb4b4b4}
Tff7b72override Tff7b72fun Td2a8ffhandleFromRadioTb4b4b4(Te6edf3bytesTb4b4b4: Te6edf3ByteArrayTb4b4b4) Tb4b4b4{
Te6edf3_receivedDataTb4b4b4.Te6edf3trySendTb4b4b4(Te6edf3bytesTb4b4b4)
Tb4b4b4}
Tff7b72override Tff7b72fun Td2a8ffresetReceivedBufferTb4b4b4(Tb4b4b4) Tb4b4b4{
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffEmptyWhileBlockTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffControlFlowWithEmptyBodyTa5d6ff"Tb4b4b4)
Tff7b72while Tb4b4b4(Te6edf3_receivedDataTb4b4b4.Te6edf3tryReceiveTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3isSuccessTb4b4b4) Tffa657Unit
Tb4b4b4}
T8b949e// --- Helper methods for testing ---
Tff7b72fun Td2a8ffemitFromRadioTb4b4b4(Te6edf3bytesTb4b4b4: Te6edf3ByteArrayTb4b4b4) Tb4b4b4{
Te6edf3_receivedDataTb4b4b4.Te6edf3trySendTb4b4b4(Te6edf3bytesTb4b4b4)
Tb4b4b4}
Tff7b72fun Td2a8ffsetConnectionStateTb4b4b4(Te6edf3stateTb4b4b4: Te6edf3ConnectionStateTb4b4b4) Tb4b4b4{
Te6edf3_connectionStateTb4b4b4.Te6edf3value Tff7b72= Te6edf3state
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.4.2 - Generated in 0.07s